package com.woniuxy.service.impl;

import com.woniuxy.mapper.MoneyHistoryMapper;
import com.woniuxy.service.MoneyHistoryService;
import com.woniuxy.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author jia
 * @create 2019/9/27
 * @since 1.0.0
 */
@Service
public class MoneyHistoryServiceImpl implements MoneyHistoryService {

    @Autowired
    public MoneyHistoryMapper moneyHistoryMapper;

    @Override
    public List<Map> selectMoneyByDay(String date) {
        //创建map list
        List<Map> mapList = new ArrayList<>();
        //创建时间格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //当前时间
        //Date date = new Date();
        //转为固定格式
        String preday = date;
        try {
            for (int i = 0; i < 7; i++) {
                Map<String, String> map = new HashMap();
                //获取前一天时间
                preday = DateUtil.getDate(preday);
                //System.out.println(preday);
                //查询当天总收入
                Double money = moneyHistoryMapper.selectMoneyByDay(preday);
                //System.out.println(money);
                //将金额转为string，并存入map
                String dayMoney = money + "";
                map.put("time", preday);
                map.put("money", dayMoney);
                //将map存入list列表
                mapList.add(map);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mapList;
    }

    @Override
    public List<Map> selectMoneyByType() {
        //创建map list
        List<Map> mapList = new ArrayList<>();
        Map<String, String> map1 = new HashMap();
        Double money1 = moneyHistoryMapper.selectMoneyByType(0);
        System.out.println("money1"+money1);
        String typeMoney1 = money1 + "";
        map1.put("value", typeMoney1);
        map1.put("name", "手续费");
        Map<String, String> map2 = new HashMap();
        Double money2 = moneyHistoryMapper.selectMoneyByType(1);
        System.out.println("money2"+money2);
        String typeMoney2 = money2 + "";
        map2.put("value", typeMoney2);
        map2.put("name", "充值");
        Map<String, String> map3 = new HashMap();
        Double money3 = moneyHistoryMapper.selectMoneyByType(2);
        System.out.println("money3"+money3);
        String typeMoney3 = money3 + "";
        map3.put("value", typeMoney3);
        map3.put("name", "提现");
        Map<String, String> map4 = new HashMap();
        Double money4 = moneyHistoryMapper.selectMoneyByType(3);
        System.out.println("money4"+money4);
        String typeMoney4 = money4 + "";
        map4.put("value", typeMoney4);
        map4.put("name", "违约金");
        mapList.add(map1);
        mapList.add(map2);
        mapList.add(map3);
        mapList.add(map4);
        return mapList;
    }
}
